﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CSharpAlgorithm
{
    class PDNA
    {
        private bool findResult = false;
        private int findEnd = 0;
        public PDNA()
        {
            int C = GetConsole.GetInt();
            for (int T = 0; T < C; T++)
            {
                //입력
                int N = GetConsole.GetInt();
                List<string> piece = new List<string>();
                for (int i = 0; i < N; i++)
                {
                    string inString = GetConsole.GetString();
                    piece.Add(inString);
                }
                //처리
                piece.Sort();
                findResult = false;
                for(int i=0;i<piece.Count;i++)
                {
                    List<string> pieceCopy = new List<string>(piece);
                    pieceCopy.Remove(piece[i]);
                    FindResult(pieceCopy, piece[i]);
                }

            }
            GetConsole.GetString();
        }
        private void FindResult(List<string> piece, string result)
        {
            if (findResult)
            { return; }

            if (piece.Count == 0)
            {
                findEnd++;
                if (CheckResult(result))
                {
                    Console.WriteLine(findEnd);
                    findResult = true;
                    Console.WriteLine(result);
                    return;
                }
            }
            
            for (int i = 0; i < piece.Count; i++)
            {
                List<string> pieceCopy = new List<string>(piece);
                pieceCopy.Remove(piece[i]);
                FindResult(pieceCopy, result + piece[i]);
            }
        }
        private bool CheckResult(string result)
        {
            for (int i = 0; i < result.Length; i++)
            {
                if (result[i] != result[result.Length - i - 1])
                { return false; }
            }
            return true;
        }
    }
}
